<template>
	<view class="moneyBox" @click="toCashList">
		<text class="tip">截止昨日可提取收益（元）</text>
		<span class="cashBox">
			<text class="moneyNum">{{freeMoney}}</text>
		</span>
		<button class="cashBtn" @click.prevent="cashFun">提 现</button>
		<view class="line"></view>
		<view class="freezeBox">
			<text class="tip">冻结收益（元）</text>
			<text class="moneyNum" style="color: rgba(229, 229, 229, 1); margin-top: 40px ;">{{waitMoney}}</text>
		</view>
		<view class="beforeBox">
			<text class="tip">已提现收益（元）</text>
			<text class="moneyNum" style="color: rgba(229, 229, 229, 1); margin-top: 40px">{{cashMoney}}</text>
		</view>
	</view>
</template>

<script>
	import api from '../../api/api'
	import {
		parseUserData
	} from '../../hook/auth.js'
	export default {
		data() {
			return {
				freeMoney: 0, //可提现金额
				waitMoney: 0, //冻结金额
				cashMoney: 0, //已提现金额
				curRoute:"",//当前路由
			}
		},
		methods: {
			//获取金额
			getMoney() {
				const self = this
				uni.login({
					provider: 'weixin', //获取微信的code
					success: function(loginRes) {
						console.log(loginRes);
						const js_code = loginRes.code
						//访问后台获取微信openId
						api.getMoney({
							js_code: js_code
						}).then(res => {
							console.log(res)
							self.freeMoney = (res.data.money / 100).toFixed(2)
							self.waitMoney = (res.data.waitMoney / 100).toFixed(2)
							self.cashMoney = (res.data.cashMoney / 100).toFixed(2)
						})
					}
				})
			},
			//提现按钮
			cashFun() {
				if(this.freeMoney==0){
					uni.showToast({
						title: '金额为0，无法提现',
						 icon: 'none'
					})
					return false
				}
				this.goto("/pages/index/cashInfo/cashInfo")
			},
			//查看明细
			toCashList(){
				if(this.curRoute!="pages/index/me/cash"){
					this.goto("/pages/index/me/cash")
				}
			},
			//路由跳转
			goto(url){
				console.log(url)
				uni.navigateTo({
					url: url
				})
			},
		},
		mounted() {
			let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
			this.curRoute = routes[routes.length - 1].route // 获取当前页面路由，也就是最后一个打开的页面路由
			if (parseUserData().openid) {
				this.getMoney()
			}
		}
	}
</script>

<style scoped>
	.freezeBox,
	.beforeBox {
		width: 50%;
		display: inline-block;
		position: relative;
	}

	.line {
		position: relative;
		width: 95%;
		height: 0px;
		border-bottom: 1px solid rgba(87, 87, 87, 1);
		margin: 0 auto;
	}

	.cashBox {
		display: block;
		position: relative;
		top: 20px;
		width: 100%;
		height: 60px;
	}

	.moneyNum {
		position: absolute;
		left: 16px;
		font-size: 20px;
		color: rgba(18, 205, 217, 1);
	}

	.cashBtn {
		position: absolute;
		top: 30%;
		right: 11px;
		width: 60px;
		height: 26px;
		display: inline;
		font-size: 10.4px;
		color: rgba(255, 255, 255, 1);
		background-color: rgba(18, 205, 217, 1);
		border: 0.74pxsolidrgba (0, 186, 173, 1);
		box-shadow: 0px0.74px1.49pxrgba (67, 207, 124, 0.25);
		border-radius: 16.53px;
	}

	.tip {
		display: inline-block;
		margin-left: 16px;
		margin-top: 14px;
		font-size: 12px;
		color: rgba(229, 229, 229, 1);
	}

	.moneyBox {
		width: 100%;
		height: 170px;
		position: relative;
		background-image: url(/static/home/矩形 1@3x.png);
		background-size: 100% 100%;
		background-repeat: no-repeat;
		padding-top: 1px;
	}
</style>